package it.disim.tlp.webreputation.business.impl;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBConnect {
	
	//Static instance of connection, only one will ever exist
		private static Connection connection = null;		
		//Returns single instance of connection
		public static Connection getConnection(){		
			//If instance has not been created yet, create it
			if(DBConnect.connection == null){
				initConnection();
			}
			return DBConnect.connection;
		}	
		//Gets JDBC connection instance
		private static void initConnection(){			
			try{		
				Class.forName("com.mysql.jdbc.Driver");		
				
				String url = "jdbc:mysql://localhost/dashboard";
				String user = "root";
				String pw = "root";
				DBConnect.connection = DriverManager.getConnection(url, user, pw);		
			}
			catch (ClassNotFoundException e){		
				System.out.println(e.getMessage());
				System.exit(0);
			}
			catch (SQLException e){			
				System.out.println(e.getMessage());
				System.exit(0);
			}
			catch (Exception e){		
			}		
		}

}
